﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.Utils;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;

namespace RecruitStudents.Utility.Helper
{
    public class DevHelper
    {
        //private static WaitDialogForm wdf = new WaitDialogForm("提示", "正在加载努力中。。。");
        static DevHelper()
        {
            //wdf.Hide();
        }

        #region 加载Loading操作共用方法
        public static void ShowWaiting()
        {
            // wdf.Show();

        }
        public static void HideWaiting()
        {
            // wdf.Hide();
        }
        #endregion

        #region 提示框通用方法

        public static void ShowErrorMessageBox(string msg)
        {
            XtraMessageBox.Show(msg, "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Error);

        }
        public static void ShowWarningMessageBox(string msg)
        {
            XtraMessageBox.Show(msg, "警告信息", MessageBoxButtons.OK, MessageBoxIcon.Warning);

        }

        public static void ShowInfoMessageBox(string msg)
        {
            XtraMessageBox.Show(msg, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);

        }
        #endregion


        /// <summary>
        /// 列表搜索结果为空的显示文字
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public static void SetGridViewSearchNullResultDisplay(object sender, CustomDrawEventArgs e)
        {
            DevExpress.XtraGrid.Views.Grid.GridView view = sender as DevExpress.XtraGrid.Views.Grid.GridView;

            if (view.RowCount != 0) return;

            StringFormat drawFormat = new StringFormat();

            drawFormat.Alignment = drawFormat.LineAlignment = StringAlignment.Center;

            e.Graphics.DrawString("暂无记录！", e.Appearance.Font, SystemBrushes.ControlDark, new RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height), drawFormat);
        }

        #region GridView、ListBoxControl控件双击某条记录共用方法
        /// <summary>
        /// 是否为双击GridView里面的Row和Cell。
        /// </summary>
        /// <param name="gridView"></param>
        /// <returns></returns>
        public static bool IsDoubleClick(GridView gridView)
        {
            bool isDoubleClick = false;
            Point pt = gridView.GridControl.PointToClient(Control.MousePosition);
            GridHitInfo info = gridView.CalcHitInfo(pt);
            if (info.InRow || info.InRowCell)
            {
                isDoubleClick = true;
            }
            return isDoubleClick;
        }

        /// <summary>
        /// 是否为双击ListBoxControl里面的Row和Cell。
        /// </summary>
        /// <param name="gridView"></param>
        /// <returns></returns>
        public static bool IsDoubleClick(ListBoxControl listbox)
        {
            bool isDoubleClick = false;
            int index = listbox.IndexFromPoint(Control.MousePosition);
            if (index != System.Windows.Forms.ListBox.NoMatches)
            {
                isDoubleClick = true;
            }
            return isDoubleClick;
        }

        #endregion
    }
}
